*******************************
*******************************
*******************************
*******************************
*This is the do file for reproducing the information and
*results in the paper "Does Threat from COVID-19 Stimulate Attitudes Amenable to Public Cooperation? Evidence from India?,"
*which appears in the British Journal of Politics and International Relations.
*******************************
*******************************
*******************************
*******************************

***********
***********
*Set the Version of Stata
***********
***********
version 13.1



***********
***********
*Open the data
***********
***********
use "/pathway here/data_name.dta"




***********
***********
*Proportion Passing Color Instructional Manipulation Check
***********
***********
sum IMC 


***********
***********
*Proportion in COVID and Shipping Groups Passing FMC-TR
***********
***********
sum FMC_TR_passed if covid==1 & IMC == 1
sum FMC_TR_passed if shipping==1 & IMC == 1



***********
***********
*Models
***********
***********
*put DVs on 0 to 1 scale
sum important_indian
gen important_indian_01 = ((important_indian - r(min))/(r(max) - r(min)))
sum trust_people
gen trust_people_01 = ((trust_people - r(min))/(r(max) - r(min)))

*for graphing purposed, generate different names for COVID treament variable
gen covid_important_indian = covid
gen covid_trust_people = covid
gen covid_always_courteous  = covid
gen covid_never_feel_resent = covid


***********
*ITT Effects
***********
reg  important_indian_01 			i.covid_important_indian female age_10 education income  	if  IMC_passed == 1	 & FMC_TR_passed~=., level(90)
margins, dydx(covid_important_indian) post  level(90)
estimates store important_indian_reg

reg  trust_people_01 				i.covid_trust_people female age_10 education income  	if  IMC_passed == 1	 & FMC_TR_passed~=., level(90)
margins, dydx(covid_trust_people) post  level(90)
estimates store trust_people_reg

reg  sd_always_courteous 		i.covid_always_courteous female age_10 education income  	if  IMC_passed == 1	 & FMC_TR_passed~=.,  level(90)
margins, dydx(covid_always_courteous) post  level(90)
estimates store sd_always_courteous_reg

reg  sd_never_feel_resentful 	i.covid_never_feel_resent female age_10 education income  	if  IMC_passed == 1	 & FMC_TR_passed~=.,  level(90)
margins, dydx(covid_never_feel_resent) post  level(90)
estimates store sd_never_feel_resent_reg   


***********
*CACEs
***********
*first, generate a variable for getting the COVID FMC-TR correct
gen FMC_pass_covid = 0
replace FMC_pass_covid =  1 if FMC_TR_passed == 1 & treatment==2
replace FMC_pass_covid =  . if FMC_TR_passed ==.

*for graphing purposed, generate different names for FMC-TR  variable
gen FMC_pass_covid_important_indian = FMC_pass_covid
gen FMC_pass_covid_trust_people = FMC_pass_covid
gen FMC_pass_covid_always_courteous  = FMC_pass_covid
gen FMC_pass_covid_never_feel_resent = FMC_pass_covid


ivregress 2sls   important_indian_01			(FMC_pass_covid_important_indian = i.covid) female age_10 education income  	if  IMC_passed == 1	, first  level(90)
margins, dydx(FMC_pass_covid_important_indian) post level(90)
estimates store important_indian_ivreg

ivregress 2sls   trust_people_01 				(FMC_pass_covid_trust_people = i.covid) female age_10 education income  	if  IMC_passed == 1	, first level(90)
margins, dydx(FMC_pass_covid_trust_people) post level(90)
estimates store trust_people_ivreg

ivregress 2sls   sd_always_courteous 		(FMC_pass_covid_always_courteous = i.covid) female age_10 education income  	if  IMC_passed == 1	, first level(90)
margins, dydx(FMC_pass_covid_always_courteous) post level(90)
estimates store sd_always_courteous_ivreg

ivregress 2sls   sd_never_feel_resentful 	(FMC_pass_covid_never_feel_resent = i.covid) female age_10 education income  	if  IMC_passed == 1	, first level(90)
margins, dydx(FMC_pass_covid_never_feel_resent) post level(90)
estimates store sd_never_feel_resent_ivreg   




***********
*Make Results Graph (Figure 1)
***********
coefplot ///
		(important_indian_reg, offset(0)) ///
		(important_indian_ivreg, offset(0)) ///
		(trust_people_reg, offset(0)) ///
		(trust_people_ivreg, offset(0)) ///
		(sd_always_courteous_reg, offset(0)) ///
		(sd_always_courteous_ivreg, offset(0)) ///
		(sd_never_feel_resent_reg, offset(0)) ///
		(sd_never_feel_resent_ivreg, offset(0)) ///
	, scheme(s1color) xline(0, lpattern(dash) lcolor(black*.5)) ///
	grid(glcolor(gray*.2) glpattern(dash)) level(90) ///
	xtitle("Estimated Effect of COVID-19 Vignette", size(medlarge)) xlabel(-.2(0.05)0.05) xscale(range(-.2 .05))	///
	recast(scatter) mcolor(black) msize(large) legend(off)  ///
	ciopts(lpattern(solid) lcolor(black*.75)) xsize(11) scale(1.4)  /// 
	coeflabels( 1.covid_important_indian  = 	"Importance of Being Indian (ITT)"   ///
				FMC_pass_covid_important_indian  = 	"Importance of Being Indian (CACE)"   ///
				1.covid_trust_people  = "Social Trust (ITT)"    ///
				FMC_pass_covid_trust_people  = "Social Trust (CACE)"    ///
				1.covid_always_courteous  = "Always Courteous (ITT)"   ///
				FMC_pass_covid_always_courteous  = 	"Always Courteous (CACE)"    ///
				1.covid_never_feel_resent  = 	"Never Resentful (ITT)"    ///
				FMC_pass_covid_never_feel_resent  = 	"Never Resentful (CACE)"    ///
				)  ///
				graphregion(margin(small)) ///
				yline(2.5 4.5 6.5, lcolor(navy) lwidth(medthick)) 	

					

					
			
***********
*ITT and CACE Effects with Partial Pooling
***********
***tag the outcome variables for stacking
gen outcome1 = sd_always_courteous
gen outcome2 = sd_never_feel_resentful
gen outcome3 = important_indian_01
gen outcome4 = trust_people_01


***preserve the data before reshape and run the models and save the results, and increase memory available
preserve 
set matsize 6000

reshape long outcome, i(respondent_id) j(j)
sum outcome

*for graphing purposes, generate different name for COVID treament variable
gen covid_partial_pool = covid

mixed  outcome 			i.covid_partial_pool female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=. || j: covid_partial_pool , level(90) 
margins, dydx(covid_partial_pool) post level(90) 
estimates store partial_pool_reg   


*for graphing purposes, generate different name for FMC-TR  variable
gen FMC_pass_covid_partial_pool = FMC_pass_covid

*do the two-stage regression
bootstrap, seed(123): mixed  FMC_pass_covid_partial_pool 			i.covid_partial_pool female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=. & outcome~= .|| j: covid_partial_pool , level(90)     
predict FMC_pass_covid_partial_pool_hat

bootstrap, seed(123): mixed   outcome 			FMC_pass_covid_partial_pool_hat female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=. || j: FMC_pass_covid_partial_pool_hat , level(90)  
margins, dydx(FMC_pass_covid_partial_pool_hat) post level(90)
estimates store partial_pool_ivreg   

restore



		

*********** 
*ITT and CACE Effects with Scaled DV
***********
***first, generate a new summated rating scale
alpha  sd_always_courteous sd_never_feel_resentful important_indian trust_people if treatment~=1, std asis gen(scale) 

***check the variance explained by first factor, using polychoric correlation matrix 
*type "indit polychoricpca" to first install "polychoricpca"
preserve
drop if treatment==1 
polychoricpca sd_always_courteous sd_never_feel_resentful important_indian trust_people
*or
polychoric sd_always_courteous sd_never_feel_resentful important_indian trust_people 
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1) pcf
restore


*put scale on 0 to 1 scale
sum scale
gen scale_01 = ((scale - r(min))/(r(max) - r(min)))

*for graphing purposes, generate different name for COVID treament variable
gen covid_scale = covid


reg  scale_01 			i.covid_scale female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
margins, dydx(covid_scale) post  level(90)
estimates store scale_reg

*for graphing purposes, generate different name for FMC-TR  variable
gen FMC_pass_covid_scale = FMC_pass_covid

ivregress 2sls   scale_01 	(FMC_pass_covid_scale = i.covid) female age_10 education income  	if  IMC_passed == 1	& treatment~=1, first level(90)
margins, dydx(FMC_pass_covid_scale) post level(90)
estimates store scale_ivreg   




***********
*Make Results Graph with Scaling and Partial Pooling Results (Figure 2)
***********
coefplot ///
		(partial_pool_reg, offset(0)) ///
		(partial_pool_ivreg, offset(0)) ///
		(scale_reg, offset(0)) ///
		(scale_ivreg, offset(0)) ///
	, scheme(s1color) xline(0, lpattern(dash) lcolor(black*.5)) ///
	grid(glcolor(gray*.2) glpattern(dash)) level(90) ///
	xtitle("Estimated Effect of COVID-19 Vignette", size(medlarge)) xlabel(-.2(0.05)0.05) xscale(range(-.2 .05))	///
	recast(scatter) mcolor(black) msize(large) legend(off)  ///
	ciopts(lpattern(solid) lcolor(black*.75)) xsize(9) ysize(2) scale(2.25)  /// 
	coeflabels( 1.covid_scale  = 	"Summated Rating Scale (ITT)"    ///
				FMC_pass_covid_scale  = 	"Summated Rating Scale (CACE)"    ///
				1.covid_partial_pool  = 	"Partial Pooling (ITT)"    ///
				FMC_pass_covid_partial_pool_hat  = 	"Partial Pooling (CACE)"    ///
				)  ///
				graphregion(margin(small)) ///
				yline(2.5, lcolor(navy) lwidth(medthick)) 		
				

***********
*Conditional ITT Effects
***********
*conditional on gender
reg  important_indian_01 			i.covid##i.female female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##i.female female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##i.female female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##i.female female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##i.female female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


*conditional on age
reg  important_indian_01 			i.covid##c.age_10 female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##c.age_10 female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##c.age_10 female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##c.age_10 female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##c.age_10 female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


*conditional on education
reg  important_indian_01 			i.covid##c.education female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##c.education female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##c.education female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##c.education female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##c.education female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


*conditional on income
reg  important_indian_01 			i.covid##c.income female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##c.income female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##c.income female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##c.income female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##c.income female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


*conditional on minority status
reg  important_indian_01 			i.covid##i.minority female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##i.minority female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##i.minority female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##i.minority female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##i.minority female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


*conditional on ideology
reg  important_indian_01 			i.covid##c.ideo female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  trust_people_01 				i.covid##c.ideo female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)
reg  sd_always_courteous 			i.covid##c.ideo female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  sd_never_feel_resentful 		i.covid##c.ideo female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=.,  level(90)
reg  scale_01 						i.covid##c.ideo female age_10 education income  	if  IMC_passed == 1	& treatment~=1 & FMC_TR_passed~=., level(90)


